﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 总结小型案例
{
    internal class MySystem
    {
        List<User> users = new List<User>();
        public void ShowMenu()
        {
            Console.WriteLine("---欢迎使用---");
            bool IsQuit = false;
            while(!IsQuit)
            {
                Console.WriteLine("请选择你的操作：");
                Console.WriteLine("   1.注册");
                Console.WriteLine("   2.登录");
                Console.WriteLine("   3.退出系统");
                try
                {
                    int num = Convert.ToInt32(Console.ReadLine());
                    switch(num)
                    {
                        case 1:
                            Register();
                            break;
                        case 2:
                            Login();
                            break;
                        case 3:
                            IsQuit = true;
                            Console.WriteLine("感谢使用");
                            break;
                    }
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("输入错误,请重新输入~");
                    Console.ResetColor();
                }
            }
        }
        public void Register()
        {
            Console.WriteLine("请输入用户名: ");
            User user = new User();
            user.UserName = Console.ReadLine();
            Console.WriteLine("请输入密码: ");
            user.Password = Console.ReadLine();

            users.Add(user);
            Console.WriteLine("注册成功");
        }
        public void Login()
        {
            User user = new User();
            Console.WriteLine("请输入姓名: ");
            user.UserName = Console.ReadLine();
            Console.WriteLine("请输入密码: ");
            user.Password = Console.ReadLine();
            if(users.Contains(user))
            {
                Console.WriteLine("登录成功");
            }
            else
            {
                Console.WriteLine("输入的用户名或密码错误");
            }

        }
    }
}
